package it312l.group9.itorf;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "itorf.db";
    private static final String DATABASE_CREATE = "CREATE TABLE itorf(q_id INT(5) PRIMARY KEY," +
    		" q_desc CHAR(200), answer CHAR(5), ans_desc CHAR(200) );";
    		
    		

    DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    	db.execSQL(DATABASE_CREATE);
    }

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		
	}
	public Question getQuestion() {
		String query = "SELECT * FROM questions LIMIT 1";
		
		SQLiteDatabase db = this.getReadableDatabase();
		
		Cursor cursor = db.rawQuery(query, null);
		
		Question question = new Question(cursor.getString(1), Boolean.parseBoolean(cursor.getString(2)), cursor.getString(3));
		
		return question;
	}
}
